home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 March / macformat-022.iso / Shareware City / Developers / src / out-of-phase-102-c / OutOfPhase 1.02 Source / OutOfPhase Folder / CommandChooser.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-23  |  10.8 KB  |  384 lines  |  [TEXT/KAHL]

  1. /* CommandChooser.c */
  2. /*****************************************************************************/
  3. /*                                                                           */
  4. /*    Out Of Phase:  Digital Music Synthesis on General Purpose Computers    */
  5. /*    Copyright (C) 1994  Thomas R. Lawrence                                 */
  6. /*                                                                           */
  7. /*    This program is free software; you can redistribute it and/or modify   */
  8. /*    it under the terms of the GNU General Public License as published by   */
  9. /*    the Free Software Foundation; either version 2 of the License, or      */
  10. /*    (at your option) any later version.                                    */
  11. /*                                                                           */
  12. /*    This program is distributed in the hope that it will be useful,        */
  13. /*    but WITHOUT ANY WARRANTY; without even the implied warranty of         */
  14. /*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          */
  15. /*    GNU General Public License for more details.                           */
  16. /*                                                                           */
  17. /*    You should have received a copy of the GNU General Public License      */
  18. /*    along with this program; if not, write to the Free Software            */
  19. /*    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.              */
  20. /*                                                                           */
  21. /*    Thomas R. Lawrence can be reached at tomlaw@world.std.com.             */
  22. /*                                                                           */
  23. /*****************************************************************************/
  24.  
  25. #include "MiscInfo.h"
  26. #include "Audit.h"
  27. #include "Debug.h"
  28. #include "Definitions.h"
  29.  
  30. #include "CommandChooser.h"
  31. #include "EventLoop.h"
  32. #include "Screen.h"
  33. #include "Memory.h"
  34. #include "SimpleButton.h"
  35. #include "StringList.h"
  36. #include "Array.h"
  37.  
  38.  
  39. #define WINXSIZE (300)
  40. #define WINYSIZE (250)
  41.  
  42. #define SCROLLX (0)
  43. #define SCROLLY (0)
  44. #define SCROLLWIDTH (WINXSIZE)
  45. #define SCROLLHEIGHT (WINYSIZE - 10 - 21 - 10)
  46.  
  47. #define OKBUTTONWIDTH (80)
  48. #define OKBUTTONHEIGHT (21)
  49. #define OKBUTTONY (SCROLLY + SCROLLHEIGHT + 10)
  50. #define OKBUTTONX ((WINXSIZE / 4) - (OKBUTTONWIDTH / 2))
  51.  
  52. #define CANCELBUTTONWIDTH (OKBUTTONWIDTH)
  53. #define CANCELBUTTONHEIGHT (OKBUTTONHEIGHT)
  54. #define CANCELBUTTONY (OKBUTTONY)
  55. #define CANCELBUTTONX (((3 * WINXSIZE) / 4) - (OKBUTTONWIDTH / 2))
  56.  
  57.  
  58. typedef struct
  59.     {
  60.         NoteCommands            CommandValue;
  61.     } InfoRecord;
  62.  
  63.  
  64. typedef struct
  65.     {
  66.         WinType*                    ScreenID;
  67.         StringListRec*        CommandStringList;
  68.         SimpleButtonRec*    OKButton;
  69.         SimpleButtonRec*    CancelButton;
  70.     } WindowRec;
  71.  
  72.  
  73. static InfoRecord            CommandList[] =
  74.     {
  75.         /* tempo adjustments */
  76.         {eCmdRestoreTempo},
  77.         {eCmdSetTempo},
  78.         {eCmdIncTempo},
  79.         {eCmdSweepTempoAbs},
  80.         {eCmdSweepTempoRel},
  81.  
  82.         /* stereo positioning adjustments */
  83.         {eCmdRestoreStereoPosition},
  84.         {eCmdSetStereoPosition},
  85.         {eCmdIncStereoPosition},
  86.         {eCmdSweepStereoAbs},
  87.         {eCmdSweepStereoRel},
  88.  
  89.         /* surround positioning adjustments */
  90.         {eCmdRestoreSurroundPosition},
  91.         {eCmdSetSurroundPosition},
  92.         {eCmdIncSurroundPosition},
  93.         {eCmdSweepSurroundAbs},
  94.         {eCmdSweepSurroundRel},
  95.  
  96.         /* overall volume adjustments */
  97.         {eCmdRestoreVolume},
  98.         {eCmdSetVolume},
  99.         {eCmdIncVolume},
  100.         {eCmdSweepVolumeAbs},
  101.         {eCmdSweepVolumeRel},
  102.  
  103.         /* default release point adjustment values */
  104.         {eCmdRestoreReleasePoint1},
  105.         {eCmdSetReleasePoint1},
  106.         {eCmdIncReleasePoint1},
  107.         {eCmdReleasePointOrigin1},
  108.         {eCmdSweepReleaseAbs1},
  109.         {eCmdSweepReleaseRel1},
  110.  
  111.         {eCmdRestoreReleasePoint2},
  112.         {eCmdSetReleasePoint2},
  113.         {eCmdIncReleasePoint2},
  114.         {eCmdReleasePointOrigin2},
  115.         {eCmdSweepReleaseAbs2},
  116.         {eCmdSweepReleaseRel2},
  117.  
  118.         /* set the default accent values */
  119.         {eCmdRestoreAccent1},
  120.         {eCmdSetAccent1},
  121.         {eCmdIncAccent1},
  122.         {eCmdSweepAccentAbs1},
  123.         {eCmdSweepAccentRel1},
  124.  
  125.         {eCmdRestoreAccent2},
  126.         {eCmdSetAccent2},
  127.         {eCmdIncAccent2},
  128.         {eCmdSweepAccentAbs2},
  129.         {eCmdSweepAccentRel2},
  130.  
  131.         {eCmdRestoreAccent3},
  132.         {eCmdSetAccent3},
  133.         {eCmdIncAccent3},
  134.         {eCmdSweepAccentAbs3},
  135.         {eCmdSweepAccentRel3},
  136.  
  137.         {eCmdRestoreAccent4},
  138.         {eCmdSetAccent4},
  139.         {eCmdIncAccent4},
  140.         {eCmdSweepAccentAbs4},
  141.         {eCmdSweepAccentRel4},
  142.  
  143.         /* set pitch displacement depth adjustment */
  144.         {eCmdRestorePitchDispDepth},
  145.         {eCmdSetPitchDispDepth},
  146.         {eCmdIncPitchDispDepth},
  147.         {eCmdPitchDispDepthMode},
  148.         {eCmdSweepPitchDispDepthAbs},
  149.         {eCmdSweepPitchDispDepthRel},
  150.  
  151.         /* set pitch displacement rate adjustment */
  152.         {eCmdRestorePitchDispRate},
  153.         {eCmdSetPitchDispRate},
  154.         {eCmdIncPitchDispRate},
  155.         {eCmdSweepPitchDispRateAbs},
  156.         {eCmdSweepPitchDispRateRel},
  157.  
  158.         /* set pitch displacement start point, same way as release point */
  159.         {eCmdRestorePitchDispStart},
  160.         {eCmdSetPitchDispStart},
  161.         {eCmdIncPitchDispStart},
  162.         {eCmdPitchDispStartOrigin},
  163.         {eCmdSweepPitchDispStartAbs},
  164.         {eCmdSweepPitchDispStartRel},
  165.  
  166.         /* hurry up adjustment */
  167.         {eCmdRestoreHurryUp},
  168.         {eCmdSetHurryUp},
  169.         {eCmdIncHurryUp},
  170.         {eCmdSweepHurryUpAbs},
  171.         {eCmdSweepHurryUpRel},
  172.  
  173.         /* default detune */
  174.         {eCmdRestoreDetune},
  175.         {eCmdSetDetune},
  176.         {eCmdIncDetune},
  177.         {eCmdDetuneMode},
  178.         {eCmdSweepDetuneAbs},
  179.         {eCmdSweepDetuneRel},
  180.  
  181.         /* default early/late adjust */
  182.         {eCmdRestoreEarlyLateAdjust},
  183.         {eCmdSetEarlyLateAdjust},
  184.         {eCmdIncEarlyLateAdjust},
  185.         {eCmdSweepEarlyLateAbs},
  186.         {eCmdSweepEarlyLateRel},
  187.  
  188.         /* default duration adjust */
  189.         {eCmdRestoreDurationAdjust},
  190.         {eCmdSetDurationAdjust},
  191.         {eCmdIncDurationAdjust},
  192.         {eCmdSweepDurationAbs},
  193.         {eCmdSweepDurationRel},
  194.         {eCmdDurationAdjustMode},
  195.  
  196.         /* set the meter.  this is used by the editor for placing measure bars. */
  197.         /* measuring restarts immediately after this command */
  198.         {eCmdSetMeter},
  199.         /* set the measure number. */
  200.         {eCmdSetMeasureNumber},
  201.  
  202.         /* transpose controls */
  203.         {eCmdSetTranspose},
  204.         {eCmdAdjustTranspose},
  205.  
  206.         /* text marker in the score */
  207.         {eCmdMarker}
  208.     };
  209. #define CommandListLength (sizeof(CommandList) / sizeof(CommandList[0]))
  210.  
  211.  
  212. /* this thing redraws our window */
  213. static void                RedrawOurWindow(WindowRec* Window)
  214.     {
  215.         CheckPtrExistence(Window);
  216.         RedrawStringList(Window->CommandStringList);
  217.         RedrawSimpleButton(Window->OKButton);
  218.         RedrawSimpleButton(Window->CancelButton);
  219.     }
  220.  
  221.  
  222. /* display a scrolling list and let the user choose a command.  if the user cancels */
  223. /* then is returns False, otherwise True. */
  224. MyBoolean                    ChooseCommandFromList(NoteCommands* Command)
  225.     {
  226.         WindowRec*            Window;
  227.         long                        Scan;
  228.         MyBoolean                LoopFlag;
  229.         MyBoolean                DoItFlag EXECUTE(= -424);
  230.  
  231.         ERROR(Command == NIL,PRERR(ForceAbort,"ChooseCommandFromList:  Command == NIL"));
  232.         Window = (WindowRec*)AllocPtrCanFail(sizeof(WindowRec),
  233.             "ChooseCommandFromList WindowRec");
  234.         if (Window == NIL)
  235.             {
  236.              FailurePoint1:
  237.                 return False;
  238.             }
  239.         Window->ScreenID = MakeNewWindow(eModelessDialogWindow,eWindowNotClosable,
  240.             eWindowNotZoomable,eWindowNotResizable,DialogLeftEdge(WINXSIZE),
  241.             DialogTopEdge(WINYSIZE),WINXSIZE,WINYSIZE,(void (*)(void*))&RedrawOurWindow,Window);
  242.         if (Window->ScreenID == NIL)
  243.             {
  244.              FailurePoint2:
  245.                 ReleasePtr((char*)Window);
  246.                 goto FailurePoint1;
  247.             }
  248.         SetWindowName(Window->ScreenID,"Command Chooser");
  249.         Window->OKButton = NewSimpleButton(Window->ScreenID,"OK",OKBUTTONX,OKBUTTONY,
  250.             OKBUTTONWIDTH,OKBUTTONHEIGHT);
  251.         if (Window->OKButton == NIL)
  252.             {
  253.              FailurePoint3:
  254.                 KillWindow(Window->ScreenID);
  255.                 goto FailurePoint2;
  256.             }
  257.         SetDefaultButtonState(Window->OKButton,True);
  258.         Window->CancelButton = NewSimpleButton(Window->ScreenID,"Cancel",CANCELBUTTONX,
  259.             CANCELBUTTONY,CANCELBUTTONWIDTH,CANCELBUTTONHEIGHT);
  260.         if (Window->CancelButton == NIL)
  261.             {
  262.              FailurePoint4:
  263.                 DisposeSimpleButton(Window->OKButton);
  264.                 goto FailurePoint3;
  265.             }
  266.         Window->CommandStringList = NewStringList(Window->ScreenID,SCROLLX,SCROLLY,
  267.             SCROLLWIDTH,SCROLLHEIGHT,GetScreenFont(),9,StringListDontAllowMultipleSelection,
  268.             "Choose a Command");
  269.         if (Window->CommandStringList == NIL)
  270.             {
  271.              FailurePoint5:
  272.                 DisposeSimpleButton(Window->CancelButton);
  273.                 goto FailurePoint4;
  274.             }
  275.         EnableStringList(Window->CommandStringList);
  276.         for (Scan = 0; Scan < CommandListLength; Scan += 1)
  277.             {
  278.                 if (!InsertStringListElement(Window->CommandStringList,
  279.                     GetCommandName(CommandList[Scan].CommandValue),NIL,&(CommandList[Scan]),False))
  280.                     {
  281.                      FailurePoint6:
  282.                         DisposeStringList(Window->CommandStringList);
  283.                         goto FailurePoint5;
  284.                     }
  285.             }
  286.  
  287.         LoopFlag = True;
  288.         while (LoopFlag)
  289.             {
  290.                 OrdType                            X;
  291.                 OrdType                            Y;
  292.                 ModifierFlags                Modifiers;
  293.                 struct MenuItemType*    MenuItem;
  294.                 char                                KeyPress;
  295.  
  296.                 switch (GetAnEvent(&X,&Y,&Modifiers,NIL,&MenuItem,&KeyPress))
  297.                     {
  298.                         default:
  299.                             break;
  300.                         case eCheckCursor:
  301.                             SetArrowCursor();
  302.                             break;
  303.                         case eKeyPressed:
  304.                             if (KeyPress == 13)
  305.                                 {
  306.                                     FlashButton(Window->OKButton);
  307.                                     DoItFlag = True;
  308.                                     LoopFlag = False;
  309.                                 }
  310.                             else if (KeyPress == eCancelKey)
  311.                                 {
  312.                                     FlashButton(Window->CancelButton);
  313.                                     DoItFlag = False;
  314.                                     LoopFlag = False;
  315.                                 }
  316.                             break;
  317.                         case eMouseDown:
  318.                             if (SimpleButtonHitTest(Window->OKButton,X,Y))
  319.                                 {
  320.                                     if (SimpleButtonMouseDown(Window->OKButton,X,Y,NIL,NIL))
  321.                                         {
  322.                                             DoItFlag = True;
  323.                                             LoopFlag = False;
  324.                                         }
  325.                                 }
  326.                             else if (SimpleButtonHitTest(Window->CancelButton,X,Y))
  327.                                 {
  328.                                     if (SimpleButtonMouseDown(Window->CancelButton,X,Y,NIL,NIL))
  329.                                         {
  330.                                             DoItFlag = False;
  331.                                             LoopFlag = False;
  332.                                         }
  333.                                 }
  334.                             else if (StringListHitTest(Window->CommandStringList,X,Y))
  335.                                 {
  336.                                     if (StringListMouseDown(Window->CommandStringList,X,Y,Modifiers))
  337.                                         {
  338.                                             DoItFlag = True;
  339.                                             LoopFlag = False;
  340.                                         }
  341.                                 }
  342.                             break;
  343.                     }
  344.             }
  345.         ERROR((DoItFlag != True) && (DoItFlag != False),PRERR(ForceAbort,
  346.             "ChooseCommandFromList:  DoItFlag is neither true nor false"));
  347.  
  348.         if (DoItFlag)
  349.             {
  350.                 ArrayRec*                SelectionList;
  351.  
  352.                 /* find out what thing was clicked */
  353.                 SelectionList = GetListOfSelectedItems(Window->CommandStringList);
  354.                 if (SelectionList != NIL)
  355.                     {
  356.                         /* see if there really is a selection */
  357.                         if (ArrayGetLength(SelectionList) > 0)
  358.                             {
  359.                                 InfoRecord*            Info;
  360.  
  361.                                 /* recover the info record */
  362.                                 Info = (InfoRecord*)ArrayGetElement(SelectionList,0);
  363.                                 *Command = Info->CommandValue;
  364.                             }
  365.                          else
  366.                             {
  367.                                 DoItFlag = False; /* there wasn't a real selection, so cancel */
  368.                             }
  369.                         DisposeArray(SelectionList);
  370.                     }
  371.                  else
  372.                     {
  373.                         DoItFlag = False; /* out of memory, so cancel operation */
  374.                     }
  375.             }
  376.  
  377.         DisposeStringList(Window->CommandStringList);
  378.         DisposeSimpleButton(Window->OKButton);
  379.         DisposeSimpleButton(Window->CancelButton);
  380.         KillWindow(Window->ScreenID);
  381.         ReleasePtr((char*)Window);
  382.         return DoItFlag;
  383.     }
  384.